home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / sources.arc / DANG_SRC.LZH / ENC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-03  |  24.6 KB  |  942 lines

  1.  
  2.  
  3. #include<globals.h>
  4. #define    Setpalette(a)    xbios(6,a)
  5.  
  6. char parry[] = "2 klang";                 /* that -q disables intro mssg on play.ttp */
  7.                                                /* but i call it 'player' */
  8. char miss[]  = "2 swish";   
  9. char CRY[]   = "2 cry11";
  10. char CAST[]  = "2 cast1";
  11. char enc_intro[] = "2 encou";
  12. char engarde[]="2 engar";
  13. char explode[]="2 explo";
  14.  
  15.  
  16. /*This module has all the fight routines, it will call:
  17.  
  18.                        a hell-of-a lot of subroutines, all
  19.                        of which are inside this module....
  20.                                                             */
  21. encounter(mf_src,mf_dest,pxyarray,scr6,run)
  22. register MFDB *mf_src,*mf_dest;   /* the src and dest MFDBs!! */
  23. char *scr6;
  24. int pxyarray[8],*run;
  25.           
  26. {
  27.  int f;
  28.  char command;
  29.  int s_ave[4];
  30.  
  31.   mf_src->fd_addr =(long)scr6; /* copy address */
  32.    
  33.       
  34.       pxyarray[0] = 70;
  35.       pxyarray[1] = 93;  /* get the src rectangle */
  36.       pxyarray[2] = 192;
  37.       pxyarray[3] = 181; 
  38.       
  39.        Setpalette( pal4 );
  40.        vro_cpyfm(handle,3,pxyarray,mf_src,mf_dest);
  41.  
  42.  
  43.  invoke_tsr( enc_intro );
  44.  
  45.  
  46.  
  47.  
  48.  runner = 1;
  49.  mon_num = 1; 
  50.  mon_alive = 1;   /* set tjis = to 1 */
  51.  lvl_monsters();            /* gets monster type */
  52. v_gtext(handle,197,99,"             ");     /* clear out existing text*/
  53. v_gtext(handle,197,99,mon.name);
  54. printf("\n%s\n",mon.name);
  55.  clear_it();
  56.  amount();                  /* gets amount*/
  57.   surprise();                /* who goes first?*/
  58.   if(who_goes == 0)
  59.    {                                                 
  60.      v_justified(handle,6,19,"Denzins of this evil place",184,0,1);
  61.      v_gtext(handle,6,27,"surprise you!"); 
  62.      pause();
  63.      mon_attack();
  64.    }
  65.    if(who_goes ==1)
  66.    {
  67.      
  68.      v_justified(handle,6,19,"You surprise death itself",184,0,1);
  69.      sprintf(string,"in the form of %d ",mon_num);
  70.      v_justified(handle,6,27,string,184,0,1);
  71.      v_gtext(handle,6,35,mon.name);
  72.      v_gtext(handle,6,43,"Will you:");
  73.      v_gtext(handle,6,51,"(R)un or");
  74.      v_gtext(handle,6,59,"(F)ight");
  75.      command = Bconin(2);
  76.     if(command == 'F' || command == 'f' )
  77.     {
  78.      invoke_tsr( engarde );
  79.      char_attack();
  80.     }
  81.     else runner = 0;   /* set the RUN variable! and lets book it otta here! */
  82.      
  83.    }
  84.  alive();                         /* check to see if anyone's alive*/
  85.  
  86.   while(char_alive ==1 && runner ==1 && mon_num !=0)
  87.   /* ok, this says that IT WILL execute if:
  88.                
  89.                the character is still alive
  90.                the character hasnt not run away 
  91.         and... if there are still monsters to fight  */
  92.     {
  93.        display_user_stats();
  94.  
  95.      if(char_alive ==1)           /* well, user always goes 1st here*/
  96.      {
  97.       char_attack();
  98.        alive();
  99.      }
  100.      if(mon_alive ==1 && mon_num !=0) 
  101.                         /* last but not least, the monster. This 
  102.                            will exec. if the moster is still alive,
  103.                            AND you didnt just kill a monster */
  104.      {
  105.       mon_attack();
  106.      alive();
  107.       }
  108.     }               /* You will only get treasure if ALL monsters
  109.                        have been killed */ 
  110.    clear_it();
  111.    if(char_alive ==0) game_over();      /* for mon_alive to be 0, ALL*/
  112.  
  113.     
  114.   f=0;
  115.    if(mon_alive ==0 && runner !=0) f=treasure();       /* monsters must have been killed*/
  116.       if (f)
  117.         {
  118.          /* load up chest pic!, since mf_src already points to MISC3.DAT
  119.        (because it loaded up the monster pic) the chest pic is also
  120.        in MISC3.DAT, so just set new source coords and copy!  */
  121.       pxyarray[0] = 194;
  122.       pxyarray[1] = 3;  /* get the src rectangle */
  123.       pxyarray[2] = 316;
  124.       pxyarray[3] = 91; 
  125.       
  126.        vro_cpyfm(handle,3,pxyarray,mf_src,mf_dest);
  127.  
  128.      v_gtext(handle,6,27,"You found a chest.     ");
  129.      
  130.   /* ask if you will open/pick it, etc. It will contain potions, */
  131.   /* jewels, weapons, maps, etc.!! */
  132.      
  133.     
  134. v_gtext(handle,197,99,"     Chest    ");
  135.  
  136.     
  137.     v_gtext(handle,6,41," Will you :          ");
  138.     
  139.     v_gtext(handle,6,49,"   O - Open it. ");
  140.     v_gtext(handle,6,57,"   L - Leave it alone");
  141.     v_gtext(handle,6,65,"                     ");
  142.     v_gtext(handle,6,81,"   Thy choice : ");
  143.    do
  144.      { command = Bconin(2);
  145.      }while(command != 'o' && command!= 'O' && command !='l' && command!= 'L');
  146.    
  147.   switch(command)
  148.       {
  149.          case 'O':
  150.          case 'o':
  151.                   open_chest();
  152.                   break;
  153.       }
  154. clear_it();
  155.  
  156.     
  157.     
  158.  
  159.         }
  160. for(f=0;f<4;f++)  pxyarray[f] = s_ave[f]; /*restore array */
  161.  
  162. v_gtext(handle,259,164,"     ");      /*( erase previous gold amt*/
  163.  
  164. /* re-play sound if there was sound playing before encounter */
  165. if(CURRENT_SOUND == 1) Dosound( wind_sound );
  166.  
  167. if(CURRENT_SOUND == 4) Dosound( rain_sound );
  168.  
  169. if (runner ==0) *run =1;  
  170.  else *run=0;    /* say you ran! */
  171. }      /* end of encounter! */
  172.  
  173.  
  174.  
  175. /***********************************/
  176.  
  177.  
  178. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  179.  
  180. char_attack()
  181.  
  182. {
  183.   int good;
  184.   char comm;
  185.   
  186. good =0;                    /* good is set to 1, if user input is valid*/
  187.  
  188. clear_it();
  189. v_gtext(handle,6,19,"    ~ Fight Options ~  ");
  190. v_gtext(handle,6,43,"(F)ight             ");
  191. v_gtext(handle,6,51,"(C)ast a spell      ");
  192. v_gtext(handle,6,59,"(T)alk to monster   ");
  193. v_gtext(handle,6,67,"C(h)arm Monster     ");
  194. v_gtext(handle,6,75,"(R)un               ");
  195. v_gtext(handle,6,83,"(Y)ell a Battle Cry ");
  196. do
  197. {
  198.  comm=Bconin(2);       /* get input from keyboard*/
  199.  
  200.  switch(comm)
  201.     {
  202.      case 'H':
  203.      case 'h': Charm_monster();good=1;      break;
  204.      case 'F':
  205.      case 'f': fight();
  206.                good = 1;
  207.                break;
  208.      case 'C': 
  209.      case 'c': cast();
  210.                good=1;
  211.                break;
  212.      case 'T': 
  213.      case 't': talk();
  214.                good=1;
  215.                break;
  216.      case 'R': 
  217.      case 'r': run();
  218.                good=1;
  219.                break;
  220.      case 'Y':             /* yell... */
  221.      case 'y':battle_cry();
  222.               good=1;
  223.               break;
  224.          }     /* end of switch*/
  225.  }            /* end of do*/
  226.  while(good==0) ;          /*good is set to 0 before case, if =0*/
  227.                            /* then users choice wasnt valid */
  228. clear_it();
  229.  
  230. } /* end of char attack */
  231.  
  232.  
  233.  
  234.  
  235. /****************************************************/
  236.  
  237. /****************************************/
  238. battle_cry()
  239. {
  240.  
  241.   invoke_tsr( CRY );
  242.  
  243. }
  244. /****************************************************/
  245. /***********/
  246.  Charm_monster()
  247. {
  248.  int hit,hld_exp;
  249.  
  250.  clear_it();
  251.  hit = rnd(100); hit+=18;  /* lower limit will be 18 */
  252.  if( (user.con + (user.current_spells_active[4]*5)) >= hit)
  253.  {
  254.   v_gtext(handle,6,11,"You charmed it!!");
  255.    
  256.         hld_exp = pos_rnd((mon_lvl+1) * mon.hd);
  257.         hld_exp = abs(hld_exp);
  258.         user.exp +=hld_exp;
  259.         mon_num--;            /* subt 1 from # of monsters!*/
  260.         if(mon_num !=0)
  261.           {
  262.            sprintf(string,"You face %d more monsters  ",mon_num);
  263.            v_justified(handle,6,27,string,184,0,1);
  264.            pause();
  265.           }
  266.        if(mon_num == 0){v_gtext(handle,6,27,"You've defeated all the");
  267.                         v_gtext(handle,6,35,"monsters...");
  268.                          pause();
  269.                          mon_alive=0;  /* all monsters dead.. */
  270.                        }
  271.      }
  272.    else 
  273.     v_gtext(handle,6,11,"The monster growls..");
  274.     pause();
  275. }
  276. /***********/
  277. fight()
  278. {
  279.   
  280.   int temp_dex,temp_str,temp_mon,hit,damage,range,hld_exp;
  281.   int m_o_p; /*missed or blow parried a random number */ 
  282.  
  283.   clear_it();
  284.   temp_dex = user.dex -18;                /* if dex >18, difference is */
  285.   if(temp_dex < 0) temp_dex =0;      /* a bonus, same with STR*/
  286.   temp_str = user.str -18;
  287.   if(temp_str < 0) temp_str =0;
  288.   temp_mon = mon_num;
  289.  
  290.   hit = rnd(19);                     /* roll a 1d19*/
  291.   hit = hit +1;                      /* add 1 to it, makes it a 1d20*/
  292.   hit = hit + temp_dex;              /*add bonus*/
  293.  
  294.  
  295.  
  296.  
  297.  if(hit < hrt[mon.ac])  /* else check for miss */
  298.    {
  299.     hit=0;
  300.    }
  301. else hit = 1;
  302.   if (hit ==0)                  /* hit is set by the HRT(above code) */
  303.  {
  304.  m_o_p = rnd(2);
  305.  switch (m_o_p)
  306.    {
  307.    case 0:
  308.           invoke_tsr( parry );
  309.           v_gtext(handle,6,13,"your blow is parried  ");
  310.           break;
  311.    case 1:
  312.           invoke_tsr( miss );
  313.           v_gtext(handle,6,13,"you missed            ");
  314.           break;
  315.    }
  316.  pause();
  317.  }
  318.   if (hit ==1)                      /* well, looks like we hit em eh?*/
  319.  {     /*begin of hit 1*/
  320.   range = user.weapon_num;
  321.   damage = rnd(range);         /* get damage*/
  322.   damage = damage+temp_str +1;             /* add bonus and +1*/
  323.   damage +=user.current_spells_active[3]*5; /* add 5 point bouns if you 
  324.                                           have magical strength! */
  325.  
  326.   mon.hp = mon.hp - damage;         /* subt. from monster hp*/
  327.   sprintf(string,"You hit the %s and..",mon.name);
  328.   v_justified(handle,6,13,string,184,0,1);
  329.   if(mon.hp<1)           /* if no more hp, then he must be dead!*/
  330.     {                
  331.         v_gtext(handle,6,21,"it lets out a piercing");
  332.         v_gtext(handle,6,29,"shreak as it slumps to");
  333.         v_gtext(handle,6,37,"the ground.");
  334.         pause();
  335.         
  336.         hld_exp = pos_rnd((mon_lvl+1) * mon.hd);
  337.         hld_exp = abs(hld_exp);
  338.         user.exp +=hld_exp;
  339.         mon_num--;            /* subt 1 from # of monsters!*/
  340.         if(mon_num !=0)
  341.           {
  342.            sprintf(string,"You face %d more monsters  ",mon_num);
  343.            v_justified(handle,6,69,string,184,0,1);
  344.            pause();
  345.           }
  346.     }
  347.   if(mon.hp>0)
  348.          {
  349.          sprintf(string,"it takes %d points damage! ",damage);
  350.          v_justified(handle,6,21,string,184,0,1);
  351.          pause();
  352.          }  
  353.   if(mon_num ==0)
  354.          {
  355.          v_gtext(handle,6,61,"You have defeated all ");
  356.          v_gtext(handle,6,69,"the monsters. ");
  357.          pause();
  358.          mon_alive =0;      /* if all are dead, set mon_alive to 0 */
  359.          }
  360.   
  361.   } /*end of hit 1 */
  362.   }     /* end of fight*/
  363.  
  364.  
  365.  
  366.  
  367.  
  368. /*********/
  369. cast()             /* oooh spellcasters...my favorite */
  370.  
  371. {
  372.   char commandc; 
  373.   int temp_inte,temp_wis,temp_mon,hit,damage,range,dummy;
  374.   int max_spell_num,x,commandi;
  375.   char sp[26];  
  376.  
  377.  clear_it();
  378.   max_spell_num = 2*user.lvl;
  379.   
  380.   /* max_spell num to cast = users lvl! */
  381.   dummy =0;
  382.    /* calculate lvl to cast spells. Formula:  */
  383.    /* user.lvl*2 = max spell number you can cast*/ 
  384.   v_gtext(handle,6,11,"Cast what spell? ");
  385.   sprintf(string,"[1-%d] or e(X)it ",max_spell_num); 
  386.   v_gtext(handle,6,19,string);
  387.   do
  388.   {
  389.   commandc=Bconin(2);       /*get input*/
  390.   commandi = commandc - '0'; /* get int value, only 0-9 right now */
  391.   if (commandi == 0 ) commandi =999;
  392.   }while((( commandi > max_spell_num) || (commandi > user.sp)) && (commandc !='x' && commandc !='X')); 
  393.   
  394.  if(commandc !='X')       /*if command = 999 the dont execute! */
  395.   { 
  396.    
  397.   user.sp = user.sp - commandi; /*subtract sp*/
  398.   user.spell_num = commandi; /*set spell number into user stats*/
  399.   /* call module to convert spell 1 to a spell name and print the name */
  400.   conv_spell( commandi,sp );
  401.   clear_it();
  402.   v_gtext(handle,6,11,"You cast a");
  403.   v_gtext(handle,6,19,sp); 
  404.  
  405.  invoke_tsr( CAST );
  406.  
  407. temp_inte = user.inte -18;                /* if dex >18, difference is */
  408.   if(temp_inte < 0) temp_inte =0;      /* a bonus, same with STR*/
  409.   temp_wis = user.wis -18;
  410.   if(temp_wis < 0) temp_wis =0;
  411.   temp_mon = mon_num;
  412.  
  413.   hit = rnd(19);                     /* roll a 1d19*/
  414.   hit = hit +1;                      /* add 1 to it, makes it a 1d20*/
  415.   hit = hit + temp_wis;              /*add bonus*/
  416.  
  417.  if(hit >= hrt[mon.ac]) /* if roll is good, then set hit to 1*/
  418.     hit =1;
  419.  
  420.  else  /* else  miss */
  421.     hit=0;
  422.  
  423.   if (hit ==0)                  /* hit is set by the HRT(above code) */
  424.  {
  425.   v_gtext(handle,6,27,"it fizzes at your");
  426.   v_gtext(handle,6,35,"fingertips! ");
  427.   pause();
  428.  }
  429.   if (hit ==1)                      /* well, looks like we hit em eh?*/
  430.  {     /*begin of hit 1*/
  431.   range = user.spell_num;
  432.   range = range + user.lvl; /*add lvl bonus to range*/
  433.   damage = rnd(range);         /* get damage*/
  434.   damage = user.inte +1;             /* add bonus and +1*/
  435.   damage = abs(damage);
  436.   mon.hp = mon.hp - damage;         /* subt. from monster hp*/
  437.  
  438.   invoke_tsr( explode );   /* strike monster */
  439.  
  440.   v_gtext(handle,6,27,"it strikes the monster!");
  441.   if(mon.hp<1)           /* if no more hp, then he must be dead!*/
  442.     {                
  443.         v_gtext(handle,6,35,"The monster falls to ");
  444.         v_gtext(handle,6,43,"the ground, blood gush-");
  445.         v_gtext(handle,6,51,"ing from its wounds!!!");
  446.         pause();pause();
  447.         mon_num--;            /* subt 1 from 3 of monsters!*/
  448.         if(mon_num !=0)
  449.           {
  450.            sprintf(string,"You still face %d more ",mon_num);
  451.            v_gtext(handle,6,67,string);
  452.            v_gtext(handle,6,75,"monsters(s)");
  453.            for(hit=0;hit<999;hit++)
  454.            {
  455.             }
  456.           }
  457.     }
  458.   if(mon.hp>0)
  459.          {
  460.          sprintf(string,"it takes %d pts damage   ",damage);
  461.          v_gtext(handle,6,35,string);
  462.          }
  463.   if(mon_num ==0)
  464.          {
  465.          v_gtext(handle,6,67,"You've defeated all the");
  466.          v_gtext(handle,6,75,"monsters.");
  467.          mon_alive =0;      /* if all are dead, set mon_alive to 0 */
  468.          for(hit=0;hit<999;hit++)
  469.           {
  470.            }
  471.          }
  472.    
  473.   } /*end of hit 1 */
  474.   
  475. } /*end of if command != 999*/
  476.  
  477. pause();
  478.  
  479. } /*end of cast */
  480.  
  481.  
  482. /********/
  483. talk()
  484. {
  485. clear_it();
  486. sprintf(string,"The %s ",mon.name);
  487. v_gtext(handle,20,50,string);
  488. v_gtext(handle,20,58,"wont talk...");
  489. pause();
  490. }
  491.  
  492. /******/
  493. run()
  494. {
  495.   int run_ok;
  496.  
  497.   clear_it();
  498.  run_ok= rnd(50);
  499.  if(user.current_spells_active[1]) run_ok =1; /* if you have fleetness. you always get away..*/
  500.   if(run_ok <=24)
  501.    {
  502.      v_gtext(handle,6,19,"You got away!!!       ");
  503.     
  504.      runner=0;
  505.     
  506.     } 
  507.  if (run_ok >24)
  508.      v_gtext(handle,6,19,"You didn't get away.  ");
  509.  
  510.  
  511.       pause();
  512.  
  513. }
  514.  
  515.  
  516.  
  517.  
  518. /******************************************************/
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525. /******************/
  526. lvl_monsters()
  527. {
  528.  if(user.lvl ==1)
  529.    mon_lvl =1;
  530.  if(user.lvl >1)
  531.    {
  532.     mon_lvl = rnd(user.lvl);
  533.     if(mon_lvl ==0)
  534.       mon_lvl ++;
  535.    }
  536.     
  537. /*actually get the monster*/
  538.  
  539. strcpy(mon.name,monsters[mon_lvl].name);             /*monsters[mon_lvl].name;*/
  540. mon.ac    = monsters[mon_lvl].ac;       /*monsters[mon_lvl].ac;*/
  541. mon.hd    = monsters[mon_lvl].hd;          /*monsters[mon_lvl].hd;*/
  542. mon.hp    = monsters[mon_lvl].hp;         /*monsters[mon_lvl].hp;*/
  543. mon.weapon= monsters[mon_lvl].weapon;        /*monsters[mon_lvl].weapon;*/
  544. mon.spell = monsters[mon_lvl].spell;       /*monsters[mon_lvl].spell;*/
  545. mon.lvl   = monsters[mon_lvl].lvl;
  546.  
  547.  
  548.  
  549. }
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562. /***********/
  563.  
  564. amount()
  565. {
  566.    int range;
  567.  
  568.   
  569.  
  570.   range = user.lvl;
  571.   mon_num = rnd(range);
  572.  
  573.   if(mon_num ==0) 
  574.        mon_num++;
  575.  
  576.    mon_num = abs(mon_num);
  577.  }
  578.  
  579.  
  580. /*************/
  581.  
  582. surprise()
  583. {
  584.    int char_roll;
  585.    int mon_roll;
  586.  
  587.  
  588.  
  589.  char_roll = rnd(6);
  590.  mon_roll  = rnd(6);
  591.  
  592.  if (char_roll >= mon_roll)
  593.     who_goes =1;         /* means character goes first */
  594.  if( char_roll < mon_roll)
  595.     who_goes =0;
  596. }
  597.  
  598. /*********************/
  599. alive()
  600. {
  601.  
  602.  if(mon.hp <=0)
  603.     
  604.       mon_alive =0;
  605.      
  606.  if (user.hp <=0)
  607.      
  608.       char_alive =0;
  609.      
  610.  }
  611.  
  612.  
  613.  
  614. /*******************************/
  615.  
  616. treasure()
  617.  
  618.   /* allocates exp and gld and items */
  619.  {
  620.    int  temp_gld;
  621.    int  roller;   
  622.    char command;
  623.    
  624.  
  625.    
  626.   v_gtext(handle,197,99,"   Treasure   ");
  627.    clear_it();
  628.    roll_gold(user.lvl,user.con,mon.lvl);
  629.    roller = rnd(300);
  630.    if(user.current_spells_active[0]) roller +=250; /* gives you an 86% chance
  631.                                                  to find a chest.. if you have treasure finding!!!*/
  632.    if(roller > 290)
  633.      return 1;   /* chest!! */
  634.     else return 0;
  635.    
  636. }       
  637.  
  638. /*******************************/
  639.  open_chest()
  640.  {
  641.   char comm;
  642.   int k,roll,temp_dex,user_roll,troll,examine;
  643.   int good;
  644.    
  645.    clear_it();
  646.    good = 0; /* if 0, invalid option chosen */
  647.    examine =0;  /* if set to 1, then a trap was found */   
  648.  do
  649.  {
  650.    v_gtext(handle,6,19,"Will you :        ");
  651.    v_gtext(handle,6,27,"  O - Open it   ");
  652.    v_gtext(handle,6,35,"  E - Examine it");
  653.    v_gtext(handle,6,43,"  C - Cast spell");
  654.    v_gtext(handle,6,51,"  L - Leave it  ");
  655.    v_gtext(handle,6,59,"                ");
  656.    v_gtext(handle,6,67,"                ");
  657.    v_gtext(handle,6,74,"                ");
  658.   
  659.    comm = Bconin(2);    
  660.   
  661.    clear_it();
  662.    switch(comm)
  663.     {
  664.       case 'o':
  665.       case 'O':good =1;
  666.              if(examine == 1)
  667.               {
  668.                roll_gold(user.lvl*100,user.con,mon.lvl);
  669.               }
  670.              else
  671.              {          
  672.                  
  673.                roll = rnd(18);
  674.                user_roll = rnd(15);
  675.                temp_dex = user.dex - 18;
  676.                if(temp_dex <0) temp_dex =0;
  677.                user_roll = user_roll + temp_dex;
  678.                  if(user_roll >= roll)
  679.                      {
  680.                          roll_gold(user.lvl*100,user.con,mon.lvl);
  681.                      }
  682.                  if(user_roll < roll)
  683.                      {
  684.                       roll = rnd(3);
  685.                  if(roll ==1) v_gtext(handle,6,19,"Nothing happens");
  686.                  if(roll ==2)
  687.                      {
  688.                      v_gtext(handle,6,19,"You trigger a trap");
  689.                      roll = rnd(user.lvl+5);
  690.                      sprintf(string,"and take %d pts damage",roll);
  691.                      v_gtext(handle,6,25,string);
  692.                      } 
  693.                     }
  694.                }  /* end of else*/
  695.               break;
  696.             
  697.             
  698.       case 'e':
  699.       case 'E': /* dont set good =1 here */ 
  700.               good = 0;
  701.               roll = rnd(18);
  702.               user_roll = rnd(18);
  703.               temp_dex = user.dex -18;
  704.               if(temp_dex > 0)
  705.               {
  706.               user_roll = user_roll + temp_dex;
  707.               }
  708.               if(user_roll>=roll)
  709.               {
  710.                v_gtext(handle,6,19,"You found a trap!");
  711.                examine =1;   /* set flag to denote trap was found */
  712.               }
  713.               else 
  714.               v_gtext(handle,6,19,"You found nothing");
  715.               pause();
  716.               break;
  717.       case 'c':
  718.       case 'C':good =0;        /* just checking..dont wanna exit yet! */
  719.                if( user.sp > 5) user.sp = user.sp -5;
  720.                v_gtext(handle,6,19,"You cast a spell...");
  721.                if (user.sp < 5) 
  722.                  {
  723.                   v_gtext(handle,6,27,"Not enough sp");
  724.                   break;
  725.                  }
  726.                user.sp -= 5;       /*subt sp */ 
  727.                user_roll = rnd(30);
  728.                user_roll +=(user.wis-12);
  729.                if (user_roll > 27){ v_gtext(handle,6,27,"you found a trap!");examine=1;}
  730.               else v_gtext(handle,6,19,"You found nothing");
  731.                pause();
  732.                break;
  733.       case 'l':
  734.       case 'L': good =1;
  735.       
  736.   } /* end of switch */
  737.  pause();
  738.   } /* end of do while */
  739.    while(good == 0);
  740.  
  741.  
  742.   for(k=0;k<100;k++)
  743.        {}
  744.  }     /* end of module*/
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751. /**********************************************************/
  752.    /* monster attack */
  753.  
  754.  mon_attack()
  755.   {
  756.    
  757.     /* use A.I. to decide if the monster will attack, talk or run */
  758.     /* if attacking, decide if it will fight or cast. */
  759.  
  760.     int mhit,mdamage;
  761.     int mop; /* miss or parry.. */
  762. clear_it();
  763.  
  764.  
  765.   mhit = rnd(19);                     /* roll a 1d19*/
  766.   mhit = mhit +1;                      /* add 1 to it, makes it a 1d20*/
  767.  
  768.  mhit = mhit + mon.hd; /* add monsters hit dice to it */
  769.  if(mhit >= mhrt[user.ac]) /* if roll is good, then set hit to 1*/
  770.    {
  771.     mhit =1;
  772.    }
  773.  if(mhit < mhrt[user.ac])  /* else check for miss */
  774.    {
  775.     mhit=0;
  776.    }
  777.  
  778.   if (mhit ==0)                  /* hit is set by the HRT(above code) */
  779.  {
  780.   mop = rnd(2);
  781.   if ( mop == 0 )
  782.   {
  783.   v_gtext(handle,6,19,"The monster missed!    ");
  784.   invoke_tsr( miss );                         
  785.   }
  786.  else 
  787.    { 
  788.      v_gtext(handle,6,19,"You parry the blow!    ");
  789.      invoke_tsr( parry );
  790.    }
  791.   pause();
  792.  } 
  793.  if (mhit ==1)                      /* well, looks like we hit em eh?*/
  794.  {     /*begin of hit 1*/
  795.   mdamage = rnd(mon.weapon);         /* get damage*/
  796.   mdamage = abs(mdamage);
  797.   mdamage -=user.current_spells_active[2]; /* subtract 1 from danage if you 
  798.                                          have Protection.. */
  799.  
  800.   user.hp = user.hp - mdamage;         /* subt. from monster hp*/
  801.   v_gtext(handle,6,19,"The monster hits you and....");
  802.   if(user.hp<1)           /* if no more hp, then he must be dead!*/
  803.     {                
  804.      v_gtext(handle,6,27,"You choke on your own");
  805.      v_gtext(handle,6,35,"blood and sink to the floor!!!");
  806.      pause();  
  807.     }
  808.   if(user.hp>0)
  809.       {
  810.          sprintf(string,"You take %d points damage!",mdamage);
  811.          v_gtext(handle,6,27,string);
  812.          pause();
  813.        }
  814.   } /*end of hit 1 */
  815.   }     /* end of mon attack*/
  816.  
  817.  
  818. /*********************************************************/
  819. /* the infamous PAUSE() function */
  820.  
  821. pause()
  822. {
  823.   char tsecs;
  824.  
  825.      
  826.      for(tsecs=0;tsecs<60;tsecs++)
  827.         Vsync();
  828. }
  829.  
  830. /*****/
  831.  
  832. clear_it()
  833. {
  834. v_gtext(handle,6,8,"                       ");
  835. v_gtext(handle,6,13,"                       ");
  836. v_gtext(handle,6,19,"                       ");
  837. v_gtext(handle,6,25,"                       ");
  838. v_gtext(handle,6,31,"                       ");
  839. v_gtext(handle,6,37,"                       ");
  840. v_gtext(handle,6,43,"                       ");
  841. v_gtext(handle,6,49,"                       ");
  842. v_gtext(handle,6,55,"                       ");
  843. v_gtext(handle,6,61,"                       ");
  844. v_gtext(handle,6,67,"                       ");
  845. v_gtext(handle,6,73,"                       ");
  846. v_gtext(handle,6,79,"                       ");
  847. v_gtext(handle,6,85,"                       ");
  848. }
  849. /**********************************/
  850. /* Rolls gold, the users level is sent, and so is his con
  851.    also mon lvl is sent 
  852.  
  853.  
  854.    Also:
  855.     o    Rolls for Gems/Jewels
  856.     o    Potions!
  857.  
  858. */
  859.  
  860. roll_gold(lvl,con,mon_lvl)
  861. int lvl,con,mon_lvl;
  862. {
  863.  int troll,
  864.      extra=20,
  865.      conextra;
  866.                clear_it();
  867.                troll = rnd(18+con);
  868.                troll = abs(troll + lvl + mon_lvl);
  869.                sprintf(string,"You find %d gold!",troll);
  870.                v_gtext(handle,6,8,string);
  871.                user.gold = user.gold+troll;
  872.  
  873.                troll = abs(rnd(100));   
  874.                 /* usually you have a 10% chance of finding 
  875.                    gems/jewels/potions
  876.                    add you (CON-18) to it
  877.                 */
  878.              if(user.current_spells_active[0]) troll -=user.con; /* big bonus. */ 
  879.              conextra = user.con - 18;
  880.              if(conextra < 0 ) conextra =0;
  881.              troll -=conextra; /* bonus */      
  882.  
  883.                 if( troll < 10 )   /* extra special items found!! */
  884.                  {
  885.                  troll = abs(rnd(3));
  886.                  switch(troll) 
  887.                   {
  888.                   case 0: v_gtext(handle,6,19,"You found a Jewel!!");
  889.                           user.user_items[5]++; break;
  890.                   case 1: v_gtext(handle,6,19,"You found a Gem!!");
  891.                           user.user_items[4]++; break;
  892.                   case 2: v_gtext(handle,6,19,"You found a potion!");
  893.                           roll_for_potion(); break;
  894.                   }
  895.  
  896.                  } 
  897. }
  898.  
  899. /************************************************/
  900. /* returns a string of the form, "you cast a 'spellname' and.." 
  901. */
  902. conv_spell( s,sp )
  903. int s;
  904. char sp[];
  905.  
  906. {
  907.  
  908. if ( s == 1 )
  909.   strcpy(sp,"Magic Missle and..");
  910. if (s == 2)
  911.   strcpy(sp,"Sleep spell and..");
  912. if(s== 3)
  913.   strcpy(sp,"Fireball! and..");
  914.      
  915. if (s== 4)
  916.    strcpy(sp,"Lightning bolt and..");
  917.            
  918. if (s == 5)
  919.     strcpy(sp,"Banishment and..");
  920.       
  921. if (s == 6)
  922.     strcpy(sp,"Hold Monster and..");
  923.   
  924.     
  925. }
  926. /************************************************/
  927.  
  928. /**
  929.    Roll for potion
  930. **/
  931.  
  932. roll_for_potion()
  933. {
  934.   int troll;
  935.   
  936.   troll = abs(rnd(8));
  937.   troll +=6;   /* offset to get in range of potions. Ie if roll 0
  938.                   the add 6 to it, so you get potion1 which is 
  939.                   at cell 6 of user_items[] */
  940.   user.user_items[troll]++;
  941. }
  942.